<template>
  <div>
    <tableComponents :pagination="{ currentPage, pageSize, total: list.all_num }" @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange" @sendUserSearch="getSearch" :searchData="userSearchData" :isHaveExport="false" @toAdd="editrider"
        :isHaveAdd="false" addText="添加骑手">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" stripe v-loading="loading" header-row-class-name="head_color" tooltip-effect="dark"
            style="width: 99.8%">
          <el-table-column label="头像" min-width="100" align="center">
            <template slot-scope="scope">
              <div class="tc">
                <img style="width: 50px; height: 50px" :src="$fnc.getImgUrl(scope.row.avatar)" class="user_img" />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="用户信息" min-width="150">
            <template slot-scope="scope">
              <div class="user_table">
                <span>用户昵称：</span>
                <small>{{ scope.row.nickname || "----" }}</small>
                <br />
                <span>会员账号：</span>
                <small>{{ scope.row.username }}</small>
                <br />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="资讯标题" min-width="180">
            <template slot-scope="scope">
              {{ scope.row.news_cn || "----" }}
            </template>
          </el-table-column>

          <el-table-column label="评论内容" min-width="200">
            <template slot-scope="scope">
              {{ scope.row.content || "----" }}
            </template>
          </el-table-column>

          <el-table-column label="点赞数" min-width="100">
            <template slot-scope="scope">
              {{ scope.row.like || "0" }}
            </template>
          </el-table-column>

          <el-table-column label="操作" min-width="80">
            <template slot-scope="scope">
              <el-row class="myblank">
                <el-button :loading="$store.state.isLoading" size="mini" type="danger" @click="deleteNew(scope.row.id)">删除</el-button>
              </el-row>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>
  </div>
</template>
<script>
import { riderListSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data () {
    return {
      userSearchData: riderListSearchData,
      loading: false,
      list: [],
      pageSize: 10,
      currentPage: 1,
      searchAll: {}
    };
  },
  components: {},
  methods: {
    getSearch (obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    getNewsAll (data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      if (this.$route.query.news_id) {
        params.news_id = this.$route.query.news_id;
      }
      this.$api.getNews.news_comment_lists(params).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange (val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange (val) {
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },
    deleteNew (id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var data = { id: id };
          this.$api.getNews.news_comment_del(data).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.getNewsAll(this.searchAll);
            } else {
              this.$swal("删除失败！", res.data.result, "success");
            }
          });
        }
      });
    }
  },
  created () {
    this.getNewsAll();
  }
};
</script>

<style lang="less" scoped></style>
